package com.manor.main.fragment.community

import android.content.Context

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter

/** 社区
 * created by Qin
 * on 2020/3/28
 */
class CommunityPagerAdapter(fm: FragmentManager, private val mContext: Context) : FragmentPagerAdapter(fm) {
    private val tabTitles: Array<String>

    private var mCityFragment: NewCircleFragment? = null
    private var mFollowFragment: NewFollowFragment? = null


    init {
        tabTitles = arrayOf("最新", "关注")

    }

    override fun getItem(position: Int): Fragment {

        when (position) {
            1 -> {
                if (mFollowFragment == null) {
                    mFollowFragment = NewFollowFragment()
                }
                return mFollowFragment as NewFollowFragment
            }
            0 -> {
                if (mCityFragment == null) {
                    mCityFragment = NewCircleFragment()
                }
                return mCityFragment as NewCircleFragment
            }
            else -> {
                if (mCityFragment == null) {
                    mCityFragment = NewCircleFragment()
                }
                return mCityFragment as NewCircleFragment
            }
        }
    }

    override fun getPageTitle(position: Int): CharSequence? {
        return tabTitles[position]
    }

    override fun getCount(): Int {
        return PAGE_COUNT
    }

    fun store() {
        mCityFragment?.stopVoice()
        mFollowFragment?.stopVoice()
    }

    fun gettop(position: Int) {
        if (position == 0) {
            mCityFragment?.gettop()
        } else {
            mFollowFragment?.gettop()
        }

    }

    companion object {

        private val PAGE_COUNT = 2
    }
}
